<?php

namespace App\Models\posts;

use App\Models\base\traits\HasGoods;
use App\Models\base\traits\HasOwner;
use App\Models\base\traits\HasPostsCate;
use App\Models\base\traits\ImgTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


/**
 * App\Models\posts\Posts
 *
 * @property int $id
 * @property int $user_id 关联用户ID
 * @property int $posts_cate_id 关联分类ID
 * @property int $share_num 分享次数
 * @property int $up_num 点赞数量
 * @property int $comment_num 评论数量
 * @property int $goods_id 商品ID
 * @property int $type 类型  1 => 咨询  2=>视频
 * @property string $title 帖子标题
 * @property string $imgs 咨询图片或视频封面
 * @property string|null $url 视频链接
 * @property int $is_show 是否公开显示   1是0否
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read mixed $header_img
 * @property-read mixed $icon
 * @property mixed $icons
 * @property-read mixed $img
 * @property mixed $parameter
 * @property-read \App\Models\goods\Goods $goods
 * @property-read \App\Models\posts\PostsCate $posts_cate
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts owner($userId)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereCommentNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereGoodsId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereImgs($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereIsShow($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts wherePostsCateId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereShareNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereUpNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereUserId($value)
 * @mixin \Eloquent
 * @property-read \App\Models\posts\PostsUp $up
 * @property-read \App\Models\posts\UserFollow $follow
 * @property int $collection_num 帖子被收藏数量
 * @property string|null $deleted_at
 * @property-read \App\Models\posts\PostsCollection $collection
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\posts\Posts onlyTrashed()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereCollectionNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereDeletedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\posts\Posts withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\posts\Posts withoutTrashed()
 * @property string|null $content 帖子内容
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\posts\Posts whereContent($value)
 */
class Posts extends Model
{

    use ImgTrait,HasGoods,HasOwner,HasPostsCate,SoftDeletes;

    protected $table = 'posts';

    protected $fillable = [
        'user_id',
        'posts_cate_id',
        'goods_id',
        'type',
        'title',
        'imgs',
        'url',
        'is_show',
        'content'
    ];

    public function up()
    {
        return $this->hasOne(PostsUp::class)->where('status',1);
    }

    public function collection()
    {
        return $this->hasOne(PostsCollection::class)->where('status',1);
    }

    public function follow()
    {
        return $this->hasOne(UserFollow::class,'follow_id','user_id')
            ->where('status',1);
    }
}
